package com.wanhua.controller;

import com.wanhua.mapper.UserMapper;
import com.wanhua.pojo.User;
import com.wanhua.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;
import java.util.UUID;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private  UserMapper userMapper;

    @RequestMapping("/findAll")
    public List<User> findAll() {
        return userService.findAll();
    }


    @RequestMapping("/main")
    public String test(){
        try {
            for (int i = 0; i < 10; i++) {
                User user = new User();
                user.setUsername(UUID.randomUUID().toString());
                user.setPassword(UUID.randomUUID().toString());
                user.setAge(new Random().nextInt(20));
                userMapper.saveUser(user);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "成功";
    }

}
